package com.yun.zf.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yun.zf.common.admin.domain.ZfOrder;
import com.yun.zf.common.admin.dto.order.OrderSearchResMo;
import com.yun.zf.common.admin.model.order.CreateOrderMo;
import com.yun.zf.common.admin.model.pact.OrderSearchMo;
import com.yun.zf.common.esIndex.OrderIndexTemplate;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author cj
 * @since 2021-07-27
 */
public interface ZfOrderMapper extends BaseMapper<ZfOrder> {
    @Select("<script>" +
            " SELECT zo.id oId,zo.type,zo.amount,zo.sign_name,zo.dept_name,zo.house_id,zo.address,zo.final_price,zo.price_unit,zo.customer_id,zo.cus_name,zo.cus_iphone,zo.`status`,zo.own_name,zo.create_time from zf_order zo   WHERE 1=1 " +
            " <if test=\"search.startTime != null and search.startTime != ''  \"> and  unix_timestamp(zo.create_time) >=unix_timestamp(#{search.startTime}) </if>" +
            " <if test=\"search.endTime != null and search.endTime != ''  \"> and  unix_timestamp(zo.create_time) <![CDATA[ <= ]]> unix_timestamp(#{search.endTime}) </if>" +
            " <if test=\"search.status != null and search.status != '' \"> and  zo.status = #{search.status} </if> " +
            " <if test=\"search.type != null and search.type != '' \"> and  zo.type = #{search.type} </if> " +
            " <if test=\"search.houseId != null and search.houseId != '' \"> and  zo.house_id = #{search.houseId} </if> " +
            "  and  zo.sign_agent = #{agentNo}  and  zo.city_code=#{cityCode} and  zo.province_code = #{provCode}  " +
            "</script>")
    public List<OrderSearchResMo> getOrderSearch(@Param("search") OrderSearchMo searchMo, Long provCode, Long cityCode, int agentNo, Page<OrderSearchResMo> page);


    @Select("<script>" +
            " SELECT zo.id oId,zo.type,zo.amount,zo.sign_name,zo.dept_name,zo.house_id,zo.address,zo.final_price,zo.price_unit,zo.customer_id,zo.cus_name,zo.cus_iphone,zo.`status`,zo.own_name,zo.create_time from zf_order zo  " +
            "<foreach item='item' index='index' collection='ids' open='(' separator=',' close=')' > " +
            "  #{item} " +
            "  </foreach>" +
            "and  zo.city_code=#{cityCode} and zo.province_code=#{provCode}  " +
            "</script>")
    public List<OrderSearchResMo> getOrderList(Long provCode, Long cityCode, List<Long> ids);

    @Select("<script>" +
            " SELECT o.id,o.province_code,o.city_code,o.house_id,o.type,o.cus_name,o.cus_iphone,o.own_name,o.own_iphone,o.`status`,o.create_time from zf_order o " +
            "WHERE id=#{orderId} and city_code=#{cityCode} and province_code=#{provCode}" +
            "</script>")
    OrderIndexTemplate getOrderEs(Long provCode, Long cityCode, Long orderId);

    @Select("<script>" +
            " SELECT o.type,o.house_id,o.final_price,o.customer_id,o.pact  from zf_order  o "+
            "WHERE id=#{orderId} and city_code=#{cityCode} and province_code=#{provCode}" +
            "</script>")
    public CreateOrderMo bringOrder(Long provCode, Long cityCode, Long orderId);
}
